package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type MarksBillApi struct {
}

var marksBillService = service.ServiceGroupApp.AutoCodeServiceGroup.MarksBillService


// CreateMarksBill 创建MarksBill
// @Tags MarksBill
// @Summary 创建MarksBill
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.MarksBill true "创建MarksBill"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /marksBill/createMarksBill [post]
func (marksBillApi *MarksBillApi) CreateMarksBill(c *gin.Context) {
	var marksBill autocode.MarksBill
	_ = c.ShouldBindJSON(&marksBill)
	if err := marksBillService.CreateMarksBill(marksBill); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteMarksBill 删除MarksBill
// @Tags MarksBill
// @Summary 删除MarksBill
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.MarksBill true "删除MarksBill"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /marksBill/deleteMarksBill [delete]
func (marksBillApi *MarksBillApi) DeleteMarksBill(c *gin.Context) {
	var marksBill autocode.MarksBill
	_ = c.ShouldBindJSON(&marksBill)
	if err := marksBillService.DeleteMarksBill(marksBill); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteMarksBillByIds 批量删除MarksBill
// @Tags MarksBill
// @Summary 批量删除MarksBill
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除MarksBill"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /marksBill/deleteMarksBillByIds [delete]
func (marksBillApi *MarksBillApi) DeleteMarksBillByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := marksBillService.DeleteMarksBillByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateMarksBill 更新MarksBill
// @Tags MarksBill
// @Summary 更新MarksBill
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.MarksBill true "更新MarksBill"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /marksBill/updateMarksBill [put]
func (marksBillApi *MarksBillApi) UpdateMarksBill(c *gin.Context) {
	var marksBill autocode.MarksBill
	_ = c.ShouldBindJSON(&marksBill)
	if err := marksBillService.UpdateMarksBill(marksBill); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindMarksBill 用id查询MarksBill
// @Tags MarksBill
// @Summary 用id查询MarksBill
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.MarksBill true "用id查询MarksBill"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /marksBill/findMarksBill [get]
func (marksBillApi *MarksBillApi) FindMarksBill(c *gin.Context) {
	var marksBill autocode.MarksBill
	_ = c.ShouldBindQuery(&marksBill)
	if err, remarksBill := marksBillService.GetMarksBill(marksBill.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"remarksBill": remarksBill}, c)
	}
}

// GetMarksBillList 分页获取MarksBill列表
// @Tags MarksBill
// @Summary 分页获取MarksBill列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.MarksBillSearch true "分页获取MarksBill列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /marksBill/getMarksBillList [get]
func (marksBillApi *MarksBillApi) GetMarksBillList(c *gin.Context) {
	var pageInfo autocodeReq.MarksBillSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := marksBillService.GetMarksBillInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
